Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Nix build files #497

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Added Nix build files #497

wants to merge 1 commit into from

Conversation

Thesola10
Copy link

This PR proposal adds build files for the Nix package manager, effectively turning this project into a "Nix Flake". The rationale is that C/C++ projects usually induce a lot of interference with the local build environment, which the Nix package manager alleviates.

These files let Nix build xeus-cling with all required dependencies, allowing one to install the kernel with a single command: nix profile install github:jupyter-xeus/xeus-cling, and copying/linking the kernel definition files in ~/.nix-profile/share/jupyter/kernels into ~/.local/share/jupyter/kernels.

(another approach for installing kernel defs would be a tiny script like xcpp-install that writes kernel defs in the user's Jupyter data directory.)

As long as flake.lock is committed, all dependencies are pinned to a strict version from the upstream NixOS project. Not committing it will let dependencies update automatically, but this may make builds less reliable.

This also provides another way to create a dev environment for working on xeus-cling: running nix develop, which opens a shell with the build environment Nix itself would use to build a release of xeus-cling.

This change does not interfere with the rest of the project.

xeus
xeus-zmq
cppzmq
cling.unwrapped
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default cling package is meant for use by end-users directly, so it only provides the /bin/cling script which feeds arguments to the unwrapped version. See my comment on cxxFlags below for why it needs to be wrapped.

Comment on lines +32 to +48
cxxFlags = if useLLVMLibcxx then [
"-I" "${lib.getDev llvmPackages_9.libcxx}/include/c++/v1"
"-L" "${llvmPackages_9.libcxx}/lib"
"-l" "${llvmPackages_9.libcxx}/lib/libc++.so"
] else [
"-I" "${gcc-unwrapped}/include/c++/${gcc-unwrapped.version}"
"-I" "${gcc-unwrapped}/include/c++/${gcc-unwrapped.version}/x86_64-unknown-linux-gnu"
];

flags = [
"-nostdinc"
"-nostdinc++"
"-isystem" "${cling.unwrapped}/lib/clang/9.0.1/include"
] ++ cxxFlags ++ [
"-isystem" "${lib.getDev stdenv.cc.libc}/include"
"-isystem" "${cling.unwrapped}/include"
];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The funny thing about Nix is that it's optimized for prebuilt packages, meaning it stores dev outputs (headers, etc...) in a different path than default outputs (executables). This breaks the assumption that they exist at the same prefix, so we force xcpp to run with those flags set to our development paths.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nix flakes are basically Nix packages which specify their inputs. The flake.lock file locks those inputs to a specific commit, allowing for reproducible builds.

@detuur
Copy link

detuur commented May 13, 2024

I'm not a nix expert, but I do want a bleeding-edge cling in my jupyter without having to mess with conda dev environments. This flake is built against nixpkgs' cling, which is still stuck on 0.9. Given there exist some patches to make xeus-cling compatible with upstream cling, how can I make a flake that builds against a git version of cling?

@Thesola10
Copy link
Author

Thesola10 commented May 14, 2024

Merge this PR atop your patches and override cling from nixpkgs to point to the latest source URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants